// 封装好的第一屏
// 使用方法：FirstScreen("image/first.jpg","/login");
import 'package:flutter/material.dart';
import '../routers/application.dart';

class FirstScreen extends StatefulWidget{
    FirstScreen(this.image,this.navigatorPath);

    final String image;
    final String navigatorPath;

    @override
    _FirstScreenState createState() => _FirstScreenState();
}

class _FirstScreenState extends State<FirstScreen> with SingleTickerProviderStateMixin{

    AnimationController _animationController;
    Animation _animation;

    @override
    void initState() {
        super.initState();
        _animationController = AnimationController(vsync: this,duration: Duration(milliseconds: 5000));
        _animation = Tween(begin: 1.0,end: 1.0).animate(_animationController);
        _animation.addStatusListener((status){
            if(status == AnimationStatus.completed){
                Application.router.navigateTo(context, widget.navigatorPath);
            }
        });
        _animationController.forward();
    }

    @override
    Widget build(BuildContext context){
        return FadeTransition(
            opacity: _animation,
            child: ConstrainedBox(
                constraints: BoxConstraints.expand(),
                child: Stack(
                    children: <Widget>[
                        Container(
                            height:double.infinity,
                            child:Image.asset(
                                widget.image,
                                scale:1.0,
                                fit:BoxFit.fill
                            ),
                        ),
                        Positioned(
                            top: 50.0,
                            right: 20.0,
                            child: FlatButton(
                                color: Colors.green,
                                highlightColor: Colors.blue,
                                colorBrightness: Brightness.dark,
                                splashColor: Colors.grey,
                                shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(20.0)
                                ),
                                child: Text("跳过"),
                                onPressed: (){
                                    _animationController.dispose();
                                    Application.router.navigateTo(context, widget.navigatorPath);
                                },
                            ),
                        )
                    ],
                )
            )
        );
    }

    @override
    void dispose(){
        _animationController.dispose();
        super.dispose();
    }

}